using Microsoft.OpenApi.Models;
using Dynamic.Utils;
using DynamicApi.Test.Common;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
    options.SwaggerDoc("v1", new OpenApiInfo() { Title = "DynamicApi.Test.WebApi", Version = "v1" });
    options.DocInclusionPredicate((docName, description) => true);
    var baseDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
    var xmlFile = System.AppDomain.CurrentDomain.FriendlyName + ".xml";
    var xmlPath = Path.Combine(baseDirectory, xmlFile);
    options.IncludeXmlComments(xmlPath);
});

builder.Services.AddDynamicWebApiCore<ServiceLocalSelectController, ServiceActionRouteFactory>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}


app.UseDynamicWebApi((serviceProvider, options) =>
{
    //options.AddAssemblyOptions(typeof(MyService).Assembly);
});

app.UseAuthorization();

app.MapControllers();

app.Run();
